const Mock = require('mockjs')

const data = Mock.mock({
    'orders|10': [{
        id: '@increment',
        name: '@string("gfdgazffscfgZZFddz",4,10)',
        addTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
        code: '@id()',
        "tatol|1-100": 100,
        userName: "@cname",
        "status|0-3": 100,
    }]
})

/**
 * status
 * 0 代发货
 * 1 已取消
 * 2 待收货
 * 3 已收货
 */
var obj = {
    code: 2000,
    data: data.orders
}

// console.log(obj);



function searchOrderByCode(code) {
    var searchRes = []
    data.orders.forEach(element => {
        if (element.code == code) {
            searchRes.push(element)
        }
    });
    return searchRes;
}

function searchGoodDetailById(id) {

    const data = Mock.mock({
        'good|1': [{
            name: "山楂",
            url: "@image('200x100', '#4A7BF7', 'Hello')",
            "price|1-100": 100,
            "num|1-10": 10,
            "total|1-100": 100,
            "status|1-4": 10,
        }]
    })

    return data.good;
}

console.log(searchGoodDetailById(1))

module.exports = [
    //getAllUser 
    {
        url: '/admin/getAllOrder',
        type: 'get',
        response: config => {
            return {
                code: 20000,
                data: data.orders
            }
        }
    },
    {
        url: '/admin/toSendGood',
        type: 'post',
        response: config => {
            let { id } = config.query
            console.log(id);
            return {
                code: 20000,
                data: "success"
            }
        }
    },
    {
        url: '/admin/searchOrderByCode',
        type: 'post',
        response: config => {
            let { code } = config.query
            return {
                code: 20000,
                data: searchOrderByCode(code)
            }
        }
    },
    {
        url: '/admin/searchGoodDetailById',
        type: 'post',
        response: config => {
            let { id } = config.query
            return {
                code: 20000,
                data: searchGoodDetailById(id)
            }
        }
    }
]